package com.ruoyi.robot.controller;

import com.ruoyi.robot.mapper.MonMpaper;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 26352
 * @Date 2023/3/10 9:48
 * @Description TODO
 * @Version 1.0
 */

@Component
public class DelMongo  {

    /**
     * 注入一个mongodb层的操作对象
     */
    @Resource
    private MonMpaper monMpaper;

    @XxlJob("DelMongo")
    public ReturnT<String> demoJobHandler(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello World.");
        //查询需要删除的聊天记录
        System.out.println("线程1"+Thread.currentThread().getName());
        //使用默认时区和语言环境获得一个日历
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE,-5);

        //data转为string类型
        String presenttime = String.valueOf(cal.getTime());

        //批量删除
        monMpaper.deleteAllByPresenttimeBefore(presenttime);

        System.out.println("删除聊天记录成功！！！！！！！！！！");
        XxlJobLogger.log("XXL-JOB, Hello World end.");
        return  ReturnT.SUCCESS;
    }



}